package com.action.customer;

import com.db.customer.*;
import java.util.*;

public class ListAction {

	private int boardtype;
	private String page;
	private int curpage;
	private int totalpage;
	private List<CustomerVO> list = new ArrayList<CustomerVO>();
	private CustomerDAO customer;

	public CustomerDAO getCustomer() {
		return customer;
	}

	public void setCustomer(CustomerDAO customer) {
		this.customer = customer;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public int getCurpage() {
		return curpage;
	}

	public void setCurpage(int curpage) {
		this.curpage = curpage;
	}

	public int getTotalpage() {
		return totalpage;
	}

	public void setTotalpage(int totalpage) {
		this.totalpage = totalpage;
	}

	public void setList(List<CustomerVO> list) {
		this.list = list;
	}

	public List<CustomerVO> getList() {
		return list;
	}

	public int getBoardtype() {
		return boardtype;
	}

	public void setBoardtype(int boardtype) {
		this.boardtype = boardtype;
	}

	public String execute() throws Exception {

		curpage = 0;
		if (page == null)
			page = "1";
		curpage = Integer.parseInt(page);

		List<CustomerVO> temp = customer.customerAllData(boardtype);

		int j = 0;
		int pagecnt = (curpage * 10) - 10;
		for (int i = 0; i < temp.size(); i++) {
			if (j < 10 && i >= pagecnt) {
				CustomerVO vo = temp.get(i);
				vo.setR_count(customer.customer_replyCount(vo.getNo()));
				list.add(vo);
				j++;
			}
		}

		int count = customer.customercount(boardtype);
		totalpage = count / 10;
		if (count % 10 > 0)
			totalpage++;
		return "success";
	}

	public String boardtype() throws Exception {

		return "success";
	}
}